Part1 Neural Network Regressor

1. Import data

2.Data analysis & visualisation:

•Perform relevant and detailed statistical analysis on the data.

•Perform relevant and detailed uni, bi and multi variate analysis.Hint: Use your best analytical approach. Even you can mix match columns to create new columns which can be used for better analysis. Create your own features if required. Be highly experimental and analytical here to find relevant hidden patterns

We try PCA to reduce the features to lesser dimensions

Source - We have 2 source of data

Source1: df : The actual data imported in from the source file

Source2: df1 : PCA decomposed source data

The Signal_Strength is not normally distributed. We see that the shapiro test telling us that the data is not normally distributed. Also if a data is not normally distributed but continuous then as per Central Limit theorem with more than 30 samples the data should become a normal distribution but here it is multi modal and the range of data is from 3 to 8 which clearly tells that the target is a discrete data.

FYI: Target is discrete and does not even show a binomial or poisson distribution

Design, train, tune and test a neural network regressor.

1 PCA applied data source 2 - df1

Model1 - PCA - 4 - rmsprop optimizer - tuning Learning rate & momentum

model 2 - PCA - 4 - rmsprop optimizer - tuning Learning rate & momentum

Model3 PCA- Stochastic gradient descent - tuning Learning rate, Momentum and decay

Model4 PCA- Stochastic gradient descent - tuning Learning rate, Momentum and decay

Model5 PCA - adam optimizer - Tuning Learning rate, Momentum and Decay

Model5 PCA - adam optimizer - Tuning Learning rate, Momentum and Decay

Trying to understand the best model out of 224 models that we created

We notice that the best model is model 9 with Adam optimizer, learning rate 0.1 - training loss- 0.450810883 test loss - 0.4668022

We take the best model from above and try applying regularization techniques

We try the same model 9 with Adam optimizer, learning rate 0.1 - training loss- 0.450810883 test loss - 0.4668022 by increasing the Epochs and setting an Early stopping

We try all other models with normal data source1 - Without PCA

Most importantly we notice that there are only 1599 records which is not enough to train a Neural Network and make it learn to make better predictions. So, we try to SMOTE Oversample the data to see if it helps in prediction. Also we try it in dataset that is not decomposed.

Model 6 - without Dropout - Adam optimizer - Resampled data

We also try Batch normalisation

-> Out of 183 models, we see that Model 6 - without Dropout - Adam optimizer lr=0.05, decay=1e-2 and early stopping with patience 15 does a good job in predicting the numbers with a very low Mean Squared Error of 0.3173 for validation data and 0.21 for training data.

-> Since the model predicts a continuous number and the target is discrete we have to round the result to the nearest value. Any number that goes beyond 8 shall be retained as 0, foreg: if output rounded comes to 9, we push it to 8.

-> This model predicts all 8, 3, 5, 6, 7, 4 but we have to round off the output to nearest number. Regressor Neural Network is not the right approach for prediction of discrete values. Also we cannot conclude with models performance using a Mean squared error or Mean absolute error, we need classification report and confusion matrix.

-> Neural Networks require a lot of data to get trained, here we see that the total number of data is 1599 which is too low to train a Neural Network

Pickle the model for future use.

Part 2 - Neural Network Classfier

Import data

Data analysis & visualisation

Design, train, tune and test a neural network classifier

Model with Adam Optimizer- LR 0.08, Decay 1e-6, 500 epochs, Early stopping with patience of 15

Pickle the model for future use.

-> Even though the classes has been balanced, Neural Network requires a lot of data to learn and make good prediction.

-> We are unable to push the model's metrics and if we were to use a model for deplyment, it will be classifier2 model.

Part 3 - Clickable GUI

We could also load the picked models to make predictions.

Part 4

Import the data.

Loading the files from H5 file

Data pre-processing and visualisation - Automated with OOPS

Visuvalizing the image

Design, train, tune and test a neural network image classifier.

Hint: Use best approach to refine and tune the data or the model. Be highly experimental here to get the best accuracy out of the model.

For visuvalization we use tensorboard:

Out of 72 models built using SGD we notice that a model with

- Learning rate 0.01

- Momentum 0.8

- Decay 0.0001

- This has a training loss of 0.61 and val_loss of 0.77 and training accuracy of 80.22% and test accuracy of 77.68%

- Now, we try to add regularization (Dropout) to check if there is any improvement

With Dropout the models look much better with Training Accuracy 84.30% & Validation Accuracy 84.34% and Training loss of 0.5226 and validation loss of 0.5260.

Models overall accuracy is at 84%

1.The current input size is (42000, 32, 32) converted to (4200,1024), we will work to resize the input sample to (42000, 28,28) so that its converted to (4200,1024) 784

2. Post this we will try applying the same models with SGD and Adam Optimizer

With SGD optimizer - Model not performing well hence we stop training

With Adam optimizer with default values - Model not performing well hence we stop training

With SGD and regularization (Dropout) - Model does not train well

Plot the training loss, validation loss vs number of epochs and training accuracy, validation accuracy vs number of epochs plot and write your observations on the same

In order to display Training loss , validation loss vs no of epochs & training accuracy, validation accuracy vs number of epochs plot, i couldn't find a solution online but came across something called as TensorBoard which looks to help with all of these details with minimal efforts and hence i have posted this in the form of video as i couldnt make a copy of tensorboard to share on uploads

Steps to run TensorBoard, please run cells from heading mentioned below:

Make sure you have done "pip install TensorBoard"

- "For visuvalization we use tensorboard:"

- Open Anaconda Prompt, CD into directory where you have placed this Project7.ipynb file and then type "tensorboard --logdir logs\fit"